package com.sbr.seb.wicket.page.administration;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.spring.injection.annot.SpringBean;

import com.sbr.seb.entity.composants.Item;
import com.sbr.seb.planning.dao.ItemDao;

public class AdminItemsPage extends AdministrationBasePage {

	@SpringBean
	private ItemDao itemDao;
	
    public AdminItemsPage() {
    	super();
    	
    	add(new ListView<Item>("itemsList", itemDao.findAll()) {

			@Override
			protected void populateItem(ListItem<Item> item) {
				Item myItem = item.getModelObject();
				item.add(new Label("itemName", myItem.getName()));
				item.add(new Label("itemDescription", myItem.getDescription()));
				if (myItem.getCategory() != null) {
					item.add(new Label("itemCategory", myItem.getCategory().getName()));
				} else {
					item.add(new Label("itemCategory", ""));
				}
			}
    		
    	});
    	
    	add(new BookmarkablePageLink("addItemLink", AddItemPage.class));
    	
    }

}
